package com.gx.smart.building.ui.swap.viewmodel

import android.app.Application
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.ToastUtils
import com.gx.smart.base.BaseViewModel
import com.gx.smart.building.admin.ScheduleAppApiService
import com.gx.smart.lib.http.api.asynctask.CallBack
import com.huishi.gx.ib.grpc.lib.ib.admin.schedule.v1.AppScheduleRecordDetailResp
import com.huishi.gx.ib.grpc.lib.ib.admin.schedule.v1.RecordDto

class SwapDetailViewModel(app: Application) : BaseViewModel(app) {
    private val detail: MutableLiveData<RecordDto> = MutableLiveData()


    //交接班——详情查看
    fun queryAppScheduleRecordDetail(id: String): LiveData<RecordDto> {
        ScheduleAppApiService.getInstance().queryAppScheduleRecordDetail(id,
            object : CallBack<AppScheduleRecordDetailResp>() {
                override fun callBack(result: AppScheduleRecordDetailResp?) {
                    if (result == null) {
                        ToastUtils.showLong("服务器超时")
                        return
                    }
                    val comResp = result.comResp
                    if (comResp.code == 100) {
                        detail.value = result.content
                    } else {
                        handleServiceException(comResp)
                    }
                }
            })
        return detail
    }

}